package Storage.StorageUnitTest;

import static org.junit.Assert.*;

import java.text.ParseException;

import org.junit.Before;
import org.junit.Test;

import Object.DSException;
import Storage.DSTaskStore;
import Task.DSTask;
import Task.DSTaskList;

//@author A0103535R
/******************** Abstract Class DSTaskStoreTest *******************/
public class DSTaskStoreTest {

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testGetInstance() throws DSException {
		DSTaskStore taskStore = DSTaskStore.getInstance();
		assertTrue(taskStore != null);
	}

	@Test
	public void testAdd() throws DSException, ParseException {
		DSTaskStore taskStore = DSTaskStore.getInstance();
		DSTask task = createTask();
		
		taskStore.clearAll();
		taskStore.add(task);
		
		DSTaskList taskList = taskStore.getTaskList();
		assertTrue(taskList.size() == 1);
		assertTrue(taskList.get(0).compareTo(task) == 0);
	}

	@Test
	public void testRemove() throws DSException, ParseException {
		DSTaskStore taskStore = DSTaskStore.getInstance();
		testAdd();
		
		DSTask task = taskStore.getTaskList().get(0);		
		taskStore.remove(task.getTaskId());
		assertTrue(taskStore.getTaskList().size() == 0);
	}

	@Test
	public void testUpdate() throws DSException, ParseException {
		DSTaskStore taskStore = DSTaskStore.getInstance();
		testAdd();
		
		DSTask task = taskStore.getTaskList().get(0);
		task.setTaskName("123");
		
		taskStore.update(task);
		assertTrue(task.compareTo(taskStore.getTaskList().get(0)) == 0);
	}
	
	public DSTask createTask() throws ParseException{
		DSTask task = new DSTask();
		task.setTaskName("name");
		task.setTaskStartTime(123);
		task.setTaskEndTime(456);
		return task;
	}
}
